package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo08 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入查询页数：");
        int page=scan.nextInt();
        System.out.println("请输入查询的条数：");
        int count=scan.nextInt();
        //获取连接
        try (Connection conn=DBUtils.getConn()){
            String sql="select username from user limit ?,?";
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setInt(1,(page-1)*count);
            ps.setInt(2,count);
            ResultSet rs=ps.executeQuery();
            //遍历查询回来的所有数据
            while (rs.next()) {
                String name=rs.getString(1);
                System.out.println(name);
            }
        } catch (SQLException throwables) {
             throwables.printStackTrace();
        }
    }
}
